<template>
  <div class="mod-config">
    <el-divider content-position="left">查询条件</el-divider>
    <el-form inline label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="收货日期">
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.receiveTimeStart" value-format="yyyy-MM-dd"
                style="width: 100%;"></el-date-picker>
            </el-col>
            <el-col class="line" :span="2" style="text-align: center;">至</el-col>
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.receiveTimeEnd" value-format="yyyy-MM-dd"
                style="width: 100%;"></el-date-picker>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="商品代码">
            <el-input v-model="dataForm.goodsCode" style="width: 175px;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="商品名称">
            <el-input v-model="dataForm.goodsName" style="width: 175px;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="调拨类型">
            <el-radio v-model="dataForm.type" label="1">发出</el-radio>
            <el-radio v-model="dataForm.type" label="2">收入</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统计类型">
            <el-radio v-model="dataForm.statisticalType" label="1">品牌</el-radio>
            <el-radio v-model="dataForm.statisticalType" label="2">商品</el-radio>
            <el-radio v-model="dataForm.statisticalType" label="3">条码</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="调拨成本">
            <el-radio v-model="dataForm.priceType" label="1">含税成本</el-radio>
            <el-radio v-model="dataForm.priceType" label="2">不含税成本</el-radio>
            <el-radio v-model="dataForm.priceType" label="3">加权平均成本</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="发出仓位">
        <el-input type="textarea" v-model="dataForm.stockName" readonly>
          <!-- <el-button slot="append" @click="getStockList">选择</el-button> -->
        </el-input>
      </el-form-item>
      <el-form-item label-width="0">
        <el-button @click="getStockList">选择</el-button>
      </el-form-item>
      <el-row style="margin-top: 10px;">
        <el-form-item label-width="5px">
          <el-link :href="printUrl" target="_blank" type="primary" :disabled="isDisabled">
            <el-button type="primary" @click="getAllocationInfoList">查 询</el-button>
          </el-link>
        </el-form-item>
      </el-row>
    </el-form>
    <search-stock v-if="stockVisible" ref="stockInfo" @refreshData="getStockInfoList"></search-stock>
  </div>
</template>

<script>
  let params = ""
  import { filterParams } from "@/util/tools"
  import { getDateFormat } from "@/util/tools"
  import { mapGetters } from "Vuex"
  import { getUserInfo } from "@/api/admin/user" //根据工号 获取用户信息
  import searchStock from "@/components/business/stock-search"

  export default {
    data() {
      return {
        printUrl: "",
        isDisabled: true,
        dataForm: {
          receiveTimeStart: "",
          receiveTimeEnd: "",
          type: "1",
          statisticalType: "1",
          goodsCode: "",
          goodsName: "",
          priceType: "1",
          stockName: "",
          stockIds: [],

        },
        deptOptions: [],
        stockVisible: false
      };
    },
    computed: {
      ...mapGetters(["userInfo", "bizData"])
    },
    components: {
      searchStock
    },
    methods: {
      getAllocationInfoList() {
        if (!this.dataForm.receiveTimeStart) {
          this.$message.warning("请出入查询日期范围");
          return
        }
        if (!this.dataForm.receiveTimeEnd) {
          this.$message.warning("请出入查询日期范围");
          return
        }
        if (this.dataForm.stockIds.length == 0) {
          this.$message.warning("请选择仓库");
          return
        }
        this.isDisabled = false
        if (this.dataForm.type == 1) {
          if (this.dataForm.statisticalType == 1) {
            params = "/allocation_brand_out.cpt";
          } else if (this.dataForm.statisticalType == 2) {
            params = "/allocation_goods_out.cpt";
          } else if (this.dataForm.statisticalType == 3) {
            params = "/allocation_barcode_out.cpt";
          }
        } else if (this.dataForm.type == 2) {
          if (this.dataForm.statisticalType == 1) {
            params = "/allocation_brand_in.cpt";
          } else if (this.dataForm.statisticalType == 2) {
            params = "/allocation_goods_in.cpt";
          } else if (this.dataForm.statisticalType == 3) {
            params = "/allocation_barcode_in.cpt";
          }
        }

        let data = filterParams(this.dataForm);
        let parameter = "";
        for (let key in data) {
          parameter += "&" + key + "=" + this.dataForm[key];
        }
        this.printUrl = this.bizData.printUrl + params + parameter;
      },
      //根据工号获取员工真实名称
      getRealName(workNumber) {
        if (workNumber == "") {
          this.dataForm.createUserName = "";
          this.dataForm.createUser = "";
        } else {
          getUserInfo(workNumber).then(response => {
            if(response.data.code == '0'){
              this.dataForm.createUserName = response.data.data.realName
              this.dataForm.createUser = response.data.data.id
            }else{
              this.$message.error(response.data.msg)
            }
          })
        }
      },
      getStockList() {
        this.stockVisible = true;
        let data = [];
        if (this.dataForm.stockIds) {
          data = this.dataForm.stockIds;
        }
        this.$nextTick(() => {
          this.$refs.stockInfo.init(data);
        });
      },
      getStockInfoList(data) {
        let name = "";
        data.forEach(result => {
          this.dataForm.stockIds.push(result.id);
          name = name ? name + "," + result.name : result.name;
        });
        this.dataForm.stockName = name;
      }
    }
  };
</script>

<style lang="scss" scoped>
  .row-bg {
    background-color: #cadee8;
    // padding-left: 15px;
    padding-right: 15px;
    padding-top: 5px;
    margin-bottom: 2px;
  }
</style>
